package com.evil.application.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.evil.application.mapper.ApplicationRelevancyReportingMapper;
import com.evil.application.pojo.entity.ApplicationInfo;
import com.evil.application.pojo.entity.ApplicationRelevancyReporting;
import com.evil.application.service.ApplicationRelevancyReportingService;
import com.evil.common.core.enums.SwitchEnum;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 应用关联报表表
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Slf4j
@RestController
@AllArgsConstructor
public class ApplicationRelevancyReportingServiceImpl extends ServiceImpl<ApplicationRelevancyReportingMapper, ApplicationRelevancyReporting> implements ApplicationRelevancyReportingService {

    private final ApplicationLogServiceImpl logService;

    /**
     * 删除应用所有关联报表
     *
     * @param applicationInfo applicationInfo
     */
    @Override
    public void deleteByApp(ApplicationInfo applicationInfo) {
        List<ApplicationRelevancyReporting> relevancyReportingList = this.baseMapper.findByApplicationId(applicationInfo.getApplicationId()).stream()
                .peek(e -> e.setIsDeleted(SwitchEnum.YES.getId()))
                .collect(Collectors.toList());

        logService.saveAndCheck(this.baseMapper, ApplicationRelevancyReporting::getRelevancyReportingId, relevancyReportingList);
    }
}
